package org.fast.project.dao.po;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;

import org.fast.project.common.enums.UserAccountStatus;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

/**
 * @author : lilith·bristol
 * @program : spring-web-archetype-po
 * @description : 用户信息持久化对象
 * @date : 2020-04-20 01:18
 **/

@Data
@EqualsAndHashCode(callSuper = false)
@Table(name = "t_user")
@Entity
@DynamicInsert
@DynamicUpdate
public class UserPO extends BaseEntity<Integer> {

    /**
     * 用户表主键 自增整数
     */
    @Id
    @Column(name = "user_id", nullable = false, length = 64)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer userId;

    /**
     * 邮箱 全局唯一
     */
    @Column(name = "email", unique = true,nullable = false)
    private String email;

    /**
     * 用户名 全局唯一
     */
    @Column(name = "user_name",unique = true, nullable = false)
    private String userName;

    /**
     * 用户昵称 全局唯一
     */
    @Column(name = "nick_name", unique = true)
    private String nickName;

    /**
     * 密码 加密存储
     */
    @Column(name = "password", nullable = false)
    private String password;

    /**
     * 用户状态 值只允许 CommonStatus 中包含的值
     *
     * @see UserAccountStatus
     */
    @Column(name = "user_status", nullable = false)
    private Integer userStatus;


    /**
     * 是否锁定状态
     *
     * @return boolean
     */
    public boolean isLocked() {
        return userStatus == UserAccountStatus.LOCKED.getStatus();
    }

    /**
     * 是否有效
     *
     * @return boolean
     */
    public boolean isInValid(){
        return userStatus == UserAccountStatus.INVALID.getStatus();
    }

    @Override
    public Integer getId() {
        return userId;
    }
}

